package com.longxi.tianjintianbao.ui.adapter.multitype.equipment;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectEquipmentListDetailsListener;
import com.longxi.tianjintianbao.model.equipment.EquipmentListDetails;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class EquipmentListDetailsViewBinder extends ItemViewBinder<EquipmentListDetails, EquipmentListDetailsViewBinder.ViewHolder> {

    SelectEquipmentListDetailsListener listener;
    public EquipmentListDetailsViewBinder(SelectEquipmentListDetailsListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_equipment_list_details, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull EquipmentListDetails equipmentListDetails) {
        holder.mTvEquipment.setText(equipmentListDetails.getEquipmentname() + "-" + equipmentListDetails.getEquipmentcode() + "-" + equipmentListDetails.getBelonged() + equipmentListDetails.getAddress());
        holder.mTvStatus.setText(equipmentListDetails.getState());
        holder.mRlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(equipmentListDetails);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mRlBtn;
        TextView mTvEquipment;
        TextView mTvStatus;
        ViewHolder(View itemView) {
            super(itemView);
            mRlBtn = itemView.findViewById(R.id.rlBtn);
            mTvEquipment = itemView.findViewById(R.id.tvEquipment);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
        }
    }
}
